# -*- coding:utf-8 *-
# 项目       :    all_auto
# 文件       :    my_page_fabu.py
# 作者       :    zhangchen
# 时间       :    2021/5/28  3:22 下午
# IDE       :    PyCharm

import time
from lib.func import think_time
from page.my_page import My_page




class My_page_fabu(My_page):

#我的页面业务流程

    @think_time
    def according_to_xpath_input(self, xpath1,text):
        # 根据xpath输入
        self.input_text(self.d.xpath(xpath1), text)



    @think_time
    def my_back1(self,par1):
        #循环返回直到出现对应数据停止
        while not self.find_text(par1):
            self.d.press("back")



    @think_time
    def my_fabu_video(self):
        # 发布视频操作
        self.id_click('com.truckhome.bbs:id/iv_community_main_post')
        time.sleep(5)
        self.text_click('小视频')
        time.sleep(8)
        self.long_click('com.truckhome.bbs:id/rv_ring')
        time.sleep(1)
        self.id_click('com.truckhome.bbs:id/iv_confirm')
        time.sleep(1)
        self.input_text(self.find_text('分享您精彩的生活时刻'), '打卡领积分')
        time.sleep(0.3)
        self.id_click('com.truckhome.bbs:id/tv_publish')
        time.sleep(5)


    @think_time
    def my_fabu_tuwen(self,par1,par2,par3):
        # 发布图文操作
        self.id_click(par1)
        time.sleep(3)
        self.text_click(par2)
        time.sleep(1)
        self.input_text(self.find_text('分享您精彩的生活时刻'), '打卡领积分')
        time.sleep(0.3)
        self.id_click(par3)
        time.sleep(3)


    @think_time
    def my_panduan_shipin(self, text1, text2, test3):
        # 视频发布
        if self.find_text(text1):
            time.sleep(0.3)
            self.find_text(text1).click()
            time.sleep(1)
            if self.find_text(text2):
                time.sleep(0.3)
                self.text_click(text2)
                time.sleep(0.3)
                self.my_panduan_id()
                self.my_fabu_video()
            else:
                self.find_text(test3)



    @think_time
    def my_panduan_id(self):
        # 判断是否有对应数据，如果没有就继续
        time.sleep(0.3)
        if self.find_text('广告'):
            self.find_id('com.truckhome.bbs:id/iv_ad_popup_close').click()
        else:
            pass


    @think_time
    def my_panduan_tuwen(self,text1,text2,text3,par1,par2,par3):
        #发布图文
        if self.find_text(text1):
            time.sleep(0.3)
            self.find_text(text1).click()
            time.sleep(1)
            if self.find_text(text2):
                time.sleep(0.3)
                self.text_click(text2)
                time.sleep(0.3)
                self.my_fabu_tuwen(par1,par2,par3)
            else:
                self.find_text(text3)

    #车速计算器
    @think_time
    def speedcalculator(self):
        time.sleep(1)
        self.xpath_click('//*[@resource-id="B"]/android.widget.ListView[1]/android.view.View[4]/android.view.View[1]/android.view.View[1]')
        self.xpath_click('//*[@text="NG80自卸车"]')
        self.xpath_click('//*[@text="北奔 NG80B重卡 375马力 8X4 压裂砂罐车(CSC5310TSGND)"]')
        self.text_click('查询')
        time.sleep(0.5)
        self.sliding()
        self.text_click('请选择轮胎型号')
        self.xpath_click('//*[@text="425/65R22.5"]')


    #购车计算器
    @think_time
    def car_purchase_calculator(self):
        self.xpath_click('//*[@text="请选择"]')
        self.text_click('北奔重卡')
        self.xpath_click('//*[@text="北奔V3ET牵引车"]')
        self.xpath_click('//*[@text="北奔重卡 V3ET重卡 精英版 460马力 6X4 LNG牵引车(国六)(ND4250BG6J7Z01)"]')
        # self.xpath_click('//android.widget.ListView/android.view.View[2]/android.widget.EditText[1]','100000')
        # self.input_text('//android.widget.ListView/android.view.View[3]/android.widget.EditText[1]','500000')
        self.xpath_click('//android.widget.ListView/android.view.View[2]/android.widget.EditText[1]')
        self.send_click('100000')
        self.xpath_click('//android.widget.ListView/android.view.View[3]/android.widget.EditText[1]')
        self.send_click('500000')
        self.xpath_click('//*[@text="计算"]')


    #挂车计算器
    @think_time
    def trailer_calculator(self):
        self.d(text="当前柴油价格(元/升): 请输入范围6-10").click()
        self.d(resourceId="dieselpricesval").click()
        self.send_click("8")
        self.text_click('确定')
        self.xpath_click('//*[@text="计算"]')

    #我的地址新建
    @think_time
    def new_my_address(self):
        self.text_click('添加收货地址')
        self.d.set_fastinput_ime(False)#开启关闭原生键盘
        self.input_text(self.find_text('请输入您的姓名'), '王大锤')
        self.input_text(self.find_text('请输入您的联系方式'), '17600960626')
        self.text_click('省市、城市、区县')
        self.xpath_click('//*[@resource-id="com.truckhome.bbs:id/container"]/android.view.ViewGroup[1]')
        self.xpath_click('//*[@resource-id="com.truckhome.bbs:id/container"]/android.view.ViewGroup[1]')
        self.xpath_click('//*[@resource-id="com.truckhome.bbs:id/container"]/android.view.ViewGroup[1]')
        self.input_text(self.find_text('请输入您的详细地址'), '000号')
        self.back()
        self.text_click('保存地址')


    #我的地址编辑
    @think_time
    def address_edit(self):
        self.text_click('编辑')
        self.xpath_click('//*[@resource-id="com.truckhome.bbs:id/et_consignee_input"]')
        self.send_click('王大锤子')
        self.xpath_click('//*[@resource-id="com.truckhome.bbs:id/et_contact_information_input"]')
        self.send_click('13901234567')
        self.xpath_click('//*[@resource-id="com.truckhome.bbs:id/tv_region_input"]')
        self.xpath_click('//*[@resource-id="com.truckhome.bbs:id/container"]/android.view.ViewGroup[2]')
        self.xpath_click('//*[@resource-id="com.truckhome.bbs:id/container"]/android.view.ViewGroup[1]')
        self.xpath_click('//*[@resource-id="com.truckhome.bbs:id/container"]/android.view.ViewGroup[3]')
        self.xpath_click('//*[@resource-id="com.truckhome.bbs:id/et_detailed_address_input"]')
        self.send_click('100号')
        # self.d.set_fastinput_ime(False)
        # self.back()
        self.text_click('保存地址')


    #司机招聘更改地区
    @think_time
    def driver_recruitment(self):
        time.sleep(1)
        self.xpath_click('//*[@resource-id="__layout"]/android.view.View[1]/android.view.View[1]/android.view.View[2]/android.view.View[2]')
        time.sleep(1)
        self.xpath_click('//*[@text="河北"]')
        time.sleep(1)
        self.xpath_click('//*[@text="石家庄市"]')
        time.sleep(1)

    #卡路里发视频
    @think_time
    def publish_video(self):
        time.sleep(1)
        self.text_click('我的卡路里')
        if self.find_text('发视频'):
            self.text_click('发视频')


# 卡路里发图文
    @think_time
    def send_pictures(self):
        time.sleep(1)
        self.text_click('我的卡路里')
        if self.find_text('去发布'):
            self.text_click('去发布')
